// pages/myApplyCase/myApplyCase.js
import request from '../../utils/config.js';
import formatDate from '../../utils/util.js';
import filter from '../../utils/filter.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: wx.getSystemInfoSync().windowHeight - 40,
    duration: 1000,
    titleShow: true,
    current: 0,
    caseInfoList: [],
    list_ing:[],
    list_end:[]
  },
  goCaseDetail: function(e) {
    let caseId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../caseDescribe/caseDescribe?caseId=' + caseId,
    })
  },
  swiperChange: function (e) {
    // console.log(e)
    if (e.detail.source == "touch") {
      this.setData({ current: e.detail.current })
    }
  },
  title1: function () {
    this.setData({
      titleShow: true,
      current: 0,
    })
  },
  title2: function () {
    this.setData({
      titleShow: false,
      current: 1,
    })
  },
  getApplyCaseList: function () {

    // queryCaseOrder
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.queryCaseInfoList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  //查询案件列表
  queryCaseInfoList: function () {
    let headerInfo = {
      pageNum: "1",
      pageSize: "",
      sessionId: app.globalData.sessionId,
    }
    let bodyInfo = {
      status: "",
      beginDate: "",
      endDate: "",
      keyword: ""
    }
    let _this = this;
    wx.showLoading({ title: '加载中 ', mask: true })
    request.requestLogin_api("queryCaseInfoList", headerInfo, bodyInfo, (obj) => {
      if (obj.data.isSuccess == "T") {
        let caseInfoList = JSON.parse(obj.data.body).caseInfoList;
        console.log("获取案件列表成功==", caseInfoList)
        // let caseInfoList = new Array();
        if (caseInfoList.length > 0) {
          var list_ing = [], list_end = [];
          caseInfoList.forEach(function (e) {
            e.caseAmts = formatDate.filterFormatAmt(e.caseAmt * 1 / 10000);
            // e.status = formatDate.investStatusFilter(e.status);
            e.dateHM = filter.dateStr(e.applyDate) + ' ' + filter.timeHM(e.applyTime);
            e.bizStageStr = filter.bizStage(e.bizStage);
            e.caseAmtStr = filter.filterAmount(e.caseAmt) + filter.filterUnit(e.caseAmts);
            if (e.status == '0' || e.status == '8' || e.status == '9') {
              list_end.push(e)
            } else {
              list_ing.push(e)
            }
          });

          // app.globalData.caseInfoList = caseInfoList;
          //保存时间
          wx.setStorageSync("caseCacheTime", formatDate.formatTime(new Date()));
          _this.setData({
            caseInfoList: caseInfoList,
            list_ing: list_ing,
            list_end: list_end
          });
        }
        wx.hideLoading();
      } else {
        wx.hideLoading();
      }
    }, (obj) => {
      wx.hideLoading();
      console.log("获取案件列表失败==", obj)
      wx.showModal({
        title: "加载失败",
        content: '请尝试下拉界面重新加载',
        confirmText: '确定',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
          } else if (res.cancel) {
          }
        }
      })
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  // onPullDownRefresh: function () {

  // },

  // /**
  //  * 页面上拉触底事件的处理函数
  //  */
  // onReachBottom: function () {

  // },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})